import 'package:flutter/material.dart';

import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:jspang/components/tabbar_item.dart';
import 'package:jspang/pages/cart/cart_page.dart';
import 'package:jspang/pages/category/category_page.dart';
import 'package:jspang/pages/home/home_page.dart';
import 'package:jspang/pages/member/member_page.dart';
import 'package:jspang/provide/currentIndex.dart';
import 'package:provider/provider.dart';

class IndexPage extends StatelessWidget {
  const IndexPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
    return Selector<CurrentIndexProvider, CurrentIndexProvider>(
      selector: (context, provider) => provider,
      shouldRebuild: (pre, next) => true,
      builder: (context, value, child) {
        return Container(
          child: Scaffold(
            bottomNavigationBar: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              currentIndex: value.currentIndex,
              items: [
                TabBarItem("home", "首页"),
                TabBarItem("profile", "分类"),
                TabBarItem("profile", "购物车"),
                TabBarItem("profile", "会员中心"),
              ],
              onTap: (int index) {
                Provider.of<CurrentIndexProvider>(context,listen: false).changeIndex(index);
              },
            ),
            body: IndexedStack(
              index: value.currentIndex,
              children: <Widget>[
                HomePage(),
                CategoryPage(),
                CartPage(),
                MemberPage()
              ],
            ),
          ),
        );
      },
    );
  }
}

// class IndexPage extends StatefulWidget {
//   IndexPage({Key key}) : super(key: key);

//   @override
//   _IndexPageState createState() => _IndexPageState();
// }

// class _IndexPageState extends State<IndexPage> {
//   var _currentIndex = 0;

//   @override
//   Widget build(BuildContext context) {
//     ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
//     return
//   }
// }
